package com.atguigu.study.controller;

import com.atguigu.study.service.ChatAssistant;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther zzyy
 * @create 2025-03-11 16:44
 */
@RestController
@Slf4j
public class ChatModelController {
    @Resource
    private ChatModel chatModel;
    @Resource
    private ChatAssistant chatAssistant;

    // http://localhost:9002/chatapi/hello
    @GetMapping(value = "/chatapi/hello")
    public String hello(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt) {
        String result = chatModel.chat(prompt);

        System.out.println("通过langchain4j调用qwen-turbo-0624模型返回结果：" + result);

        return result;
    }

    // http://localhost:9002/chatapi/lowapi?prompt=%E8%8C%85%E5%8F%B0%E9%85%92%E5%A5%BD%E5%96%9D%E5%90%97
    @GetMapping(value = "/chatapi/lowapi")
    public String lowApi(@RequestParam("prompt") String prompt) {

        ChatResponse chatResponse = chatModel.chat(UserMessage.from(prompt));

        return chatResponse.aiMessage().text();
    }

    @GetMapping(value = "/chatapi/highapi")
    public String highApi(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt) {
        return chatAssistant.chat(prompt);
    }
}
